import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogManager {
    public static final String LOG_FILE = "system.log"; // 若使用data目录：改为 "data/system.log"

    public static void log(String content) {
        try {
            File f = new File(LOG_FILE);
            File parent = f.getParentFile();
            if (parent != null && !parent.exists()) {
                parent.mkdirs();
            }
            try (FileWriter fw = new FileWriter(f, true)) {
                String ts = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
                fw.write(ts + " " + content + System.lineSeparator());
            }
        } catch (IOException e) {
            System.out.println("日志写入失败: " + e.getMessage());
        }
    }
}